let db = require('../../database/sqliteCRUD/index')
const path = require("path");
const fs = require("fs");
const assert = require("assert");
const {sentence} = require("mockjs/src/mock/random/text");


let json = JSON.parse(fs.readFileSync(path.join(__dirname, '../../examples/细分类目.json'), {encoding: 'utf8'}))
describe('测试sqlite中的crud', () => {
    const people = [
        {name: "张三", age: 25},
        {name: "李四", age: 30},
        {name: "王五", age: 35},
        {name: "赵六", age: 40},
        {name: "陈七", age: 45},
        {name: "孙八", age: 50},
        {name: "周九", age: 55},
        {name: "吴十", age: 60},
        {name: "郑十一", age: 65},
        {name: "王十二", age: 70}
    ];

    it('should 测试插入数据', () => {

        for (const person of people) {
            if (person.age > 25) continue
            ((person) => {
                db.userDB.insertUser(person.name, person.age)
            })(person)

        }
    });


    it('should 测试获得表格信息', async () => {
        let data = await db.autoCRUD.getTableInfo('users')
        console.log(data)
        assert.equal(data instanceof Array, true, '正常情况返回的是数组')
    });

    it('should 测试getRows', async () => {
        let data = await db.autoCRUD.getRows('users', db.where('age>10'), db.limit(5, 20))
        console.assert(typeof data.length === 'number', 'getRows正常情况返回的内容应该是数组',)
        console.log(data)
    });

    it('should 测试 addrows', () => {
        let sentenceArr = [
            {word: '法库cadawd发挥瓦克今晚发贺卡我就会·1', time: 189780987987},
            {
                word: "手动添加引号：如果你决定手动添加引号，确保在拼接 SQL 语句时正确处理引号。可以使用字符串连接或模板字符串来确保引号正确添加。",
                time: new Date().getTime()
            }
        ]
        db.autoCRUD.addRows('users', [{name: '张碧晨', age: 29}])
        db.autoCRUD.addRows('sentence', sentenceArr)
        console.log(a, b)
    });
});
